package com.freewater.springboot.demo.aop.api.advices.before;

import com.freewater.springboot.demo.aop.api.advices.EmployeeService;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Main {

    public static void main(String[] args) {
        Main main = new Main();
        main.test();
    }

    public void test() {
        final AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(AppConfig.class);
        ProxyFactory proxyFactory = new ProxyFactory();
        SimpleBeforeAdvice simpleBeforeAdvice = new SimpleBeforeAdvice();
        proxyFactory.addAdvice(simpleBeforeAdvice);
        proxyFactory.setTarget(applicationContext.getBean(EmployeeService.class));
        // 获取代理对象
        EmployeeService proxy = (EmployeeService) proxyFactory.getProxy();
        System.out.println(proxy.getEmployeeName(1));
    }

}
